import 'package:flutter/material.dart';
import 'package:gesture_exp/custom_tap.dart';

void main() {
  runApp(MaterialApp(
    home: GestureExpPage(),
  ));
}

class GestureExpPage extends StatefulWidget {
  const GestureExpPage({Key key}) : super(key: key);

  @override
  _GestureExpPageState createState() => _GestureExpPageState();
}

class _GestureExpPageState extends State<GestureExpPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Center(
          child: Container(
            color: Colors.cyan,
            width: 200,
            height: 200,
            child: Stack(
              overflow: Overflow.visible,
              children: <Widget>[
                Positioned(
                  left: -50,
                  top: -50,
                  width: 100,
                  height: 100,
                  child: TapExpWidget(),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class TapExpWidget extends StatelessWidget {
  const TapExpWidget({
    Key key,
  }) : super(key: key);

  /// RawGestureDetector(
  ///   gestures: <Type, GestureRecognizerFactory>{
  ///     TapGestureRecognizer: GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>(
  ///       () => TapGestureRecognizer(),
  ///       (TapGestureRecognizer instance) {
  ///         instance
  ///           ..onTapDown = (TapDownDetails details) { setState(() { _last = 'down'; }); }
  ///           ..onTapUp = (TapUpDetails details) { setState(() { _last = 'up'; }); }
  ///           ..onTap = () { setState(() { _last = 'tap'; }); }
  ///           ..onTapCancel = () { setState(() { _last = 'cancel'; }); };
  ///       },
  ///     ),
  ///   },
  ///   child: Container(width: 300.0, height: 300.0, color: Colors.yellow, child: Text(_last)),
  /// )

  @override
  Widget build(BuildContext context) {
    return RawGestureDetector(
      gestures: <Type, GestureRecognizerFactory>{
        CustomTap: GestureRecognizerFactoryWithHandlers<CustomTap>(
          () => CustomTap(),
          (CustomTap instance) {
            instance
              ..onTap = () {
                print('tap red, ${DateTime.now()}');
              };
          },
        ),
      },
      child: Container(color: Colors.red),
    );
    // return GestureDetector(
    //   onTap: () {
    //     print('tap red');
    //   },
    //   child: Container(color: Colors.red),
    // );
  }
}
